/**
 * @author: Niimp
 * @date: 2023/12/1 14:15
 * @statement:
 */
package com.dmgis.hndz.service.impl;

import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.dmgis.hndz.service.MonitoringManagementService;
import com.dmgis.hndz.service.serviceUtils.MonitoringManagementUtils;
import com.dmgis.hndz.mapper.MonitoringManagementMapper;
import com.dmgis.hndz.pojo.*;
import com.dmgis.hndz.pojoVo.*;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Service
public class MonitoringManagementServiceImpl implements MonitoringManagementService {
    @Resource
    private MonitoringManagementMapper monitoringManagementMapper;

    @Resource
    private MonitoringManagementUtils monitoringManagementUtils;

    /**
     * 监测点信息
     *
     * @param jsonObject
     * @return
     */
    @Override
    public List<Jcca16AVo> queryMonitorInfo(JSONObject jsonObject) {
//        if (JSONUtil.parseObj(jsonObject).isEmpty()) {
//            return null;
//        }
        String zhaa11a030 = jsonObject.getString("cityCode");//"市编号"
        String zhaa11a032 = jsonObject.getString("countyCode");//县编号";
        String jcca16a430 = jsonObject.getString("monitoringCode");//监测点编号"
        String jcca16a020 = jsonObject.getString("monitoringName");//监测点名称"
        String zhaa11a024 = jsonObject.getString("disasterType");//灾害类型"
        String jcca16a040 = jsonObject.getString("monitoringType");//监测点类型"

        if (StringUtils.isEmpty(zhaa11a030)){
            zhaa11a030 = "431200";
        }
        List<Jcca16AVo> jcca16AVoList = monitoringManagementMapper.queryMonitorInfo(zhaa11a030, zhaa11a032,jcca16a430, jcca16a020, zhaa11a024,jcca16a040);
        for (Jcca16AVo jcca16AVo : jcca16AVoList) {
            if (jcca16AVo == null) {

            }
        }

        Iterator<Jcca16AVo> iterator = jcca16AVoList.iterator();
        while (iterator.hasNext()) {
            Jcca16AVo jcca16AVo = iterator.next();
            if (jcca16AVo == null) {
                iterator.remove();
            }
        }



        return jcca16AVoList;
    }

    /**
     * 监测点传感器查询
     *
     * @return
     */
    @DS("master")
    @Override
/*    public List<MonitorAndSensorVo> queryMonitorAndSensorInfo() {
        List<MonitorAndSensorVo> list = monitoringManagementMapper.queryMonitorAndSensorInfo();
        return list;
    }*/
    public List<MonitorAndSensorVo> queryMonitorAndSensorInfo(JSONObject jsonObject){
        String currentPage = jsonObject.getString("currentPage");
        String pageSize = jsonObject.getString("pageSize");
        //查总数据条数
        int totalNum = monitoringManagementMapper.findTotalNum();
        //根据提供的参数构建一个PageUtils对象
        Page<MonitorAndSensorVo> pu = new Page<>(Integer.valueOf(currentPage), Integer.valueOf(pageSize), totalNum);
        //查当前页数据
        List<MonitorAndSensorVo> list = monitoringManagementMapper.findByPage(pu.getStartNum(), pu.getPageSize());
        //将查询到的指定页码的数据存储到分页工具对象中
        pu.setList(list);
        //将分页工具对象返回
        return list;
    }



    /**
     * 报警信息查询
     *
     * @param jsonObject
     * @return
     */
    @DS("slave_qxdata")
    @Override
    public MonitorWaringInfoVo queryMonitorWaringInfo(JSONObject jsonObject) {
        String dateTime = jsonObject.getString("dateTime");
        String startTime = jsonObject.getString("startTime");
        String endTime = jsonObject.getString("endTime");
        String waringLevel = jsonObject.getString("waringLevel");
        String waringStatus = jsonObject.getString("waringStatus");
        String dateLevel = jsonObject.getString("dateLevel");
        String jcdId = jsonObject.getString("jcdId");
        List<Jkca01aVo> list = new ArrayList<>();
        System.out.println("==============" + dateTime);
        if ("日".equals(dateLevel)) {
            list = monitoringManagementMapper.queryMonitorWaringInfo(dateTime, startTime,
                    endTime,
                    waringLevel,
                    waringStatus,
                    dateLevel,jcdId);
        } else if ("周".equals(dateLevel)) {
            list = monitoringManagementMapper.queryMonitorWaringInfoWeek(dateTime, startTime,
                    endTime,
                    waringLevel,
                    waringStatus,
                    dateLevel,
                    jcdId);
        } else if ("月".equals(dateLevel)) {
            list = monitoringManagementMapper.queryMonitorWaringInfoMonth(dateTime, startTime,
                    endTime,
                    waringLevel,
                    waringStatus,
                    dateLevel,
                   jcdId);
        } else if ("年".equals(dateLevel)) {
            list = monitoringManagementMapper.queryMonitorWaringInfoYear(dateTime, startTime,
                    endTime,
                    waringLevel,
                    waringStatus,
                    dateLevel,
                    jcdId);
        } else {
            list = monitoringManagementMapper.queryMonitorWaringInfoRange(dateTime, startTime,
                    endTime,
                    waringLevel,
                    waringStatus,
                    dateLevel,
                    jcdId);
        }

        //统计各个预警等级的数量
        Map<String, Integer> countWaringLevelMap = list.stream()
                .collect(Collectors.groupingBy(Jkca01aVo::getJkca01a020, Collectors.summingInt(e -> 1)));
        int totalCountWaringLevelMap = countWaringLevelMap.values().stream().mapToInt(Integer::intValue).sum();
        countWaringLevelMap.put("总计", totalCountWaringLevelMap);
        //统计各个预警等级的短信数
        Map<String, Integer> countWaringSMS = list.stream()
                .filter(Jkca01aVo -> "0".equals(Jkca01aVo.getJkca01g100()))
                .collect(Collectors.groupingBy(Jkca01aVo::getJkca01a020, Collectors.summingInt(e -> 1)));
        int totalCountWaringSMS = countWaringSMS.values().stream().mapToInt(Integer::intValue).sum();
        countWaringSMS.put("总计", totalCountWaringSMS);
        MonitorWaringInfoVo monitorWaringInfoVo = new MonitorWaringInfoVo(list, countWaringLevelMap, countWaringSMS);
        System.out.println(monitorWaringInfoVo);
        System.out.println("+++++++++++++++++++++++++++++++++++++++++++");
        return monitorWaringInfoVo;
    }

    /**
     * 位移
     *
     * @param jsonObject 请求的JSON对象
     * @return 检测曲线结果
     */
    @DS("master")
    @Override
    public DetectionCurveResultVo queryDetectionCurve(JSONObject jsonObject) {
        String countLevel = jsonObject.getString("countLevel");
        String dateTime = jsonObject.getString("dateTime");
        String startTime = jsonObject.getString("startTime");
        String endTime = jsonObject.getString("endTime");
        String dateLevel = jsonObject.getString("dateLevel");
        String monitorCode = jsonObject.getString("monitorCode");

        List<Jcaa02a> list = new ArrayList<>();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

        // 根据dateLevel查询相应的检测曲线数据
        if ("1".equals(dateLevel)) {
            list = monitoringManagementMapper.queryDetectionCurveToday(dateTime, startTime, endTime, monitorCode);
        } else if ("3".equals(dateLevel)) {
            list = monitoringManagementMapper.queryDetectionCurveThreeDay(dateTime, startTime, endTime, monitorCode);
        } else if ("7".equals(dateLevel)) {
            list = monitoringManagementMapper.queryDetectionCurveSevenDay(dateTime, startTime, endTime, monitorCode);
        } else if ("15".equals(dateLevel)) {
            list = monitoringManagementMapper.queryDetectionCurveFifteenDay(dateTime, startTime, endTime, monitorCode);
        } else if ("30".equals(dateLevel)) {
            list = monitoringManagementMapper.queryDetectionCurveThirty(dateTime, startTime, endTime, monitorCode);
        } else {
            list = monitoringManagementMapper.queryDetectionCurve(dateTime, startTime, endTime, monitorCode);
        }

        // 将Jcaa02a对象转换为DetectionCurveVo对象
        List<DetectionCurveVo> listX = list.stream()
                .map(Jcaa02a -> new DetectionCurveVo(Jcaa02a.getJcaa02a040(), Jcaa02a.getJcca31b030(),
                        Jcaa02a.getJcca31b180(), Jcaa02a.getJcaa02a050()))
                .collect(Collectors.toList());

        List<DetectionCurveVo> listY = list.stream()
                .map(Jcaa02a -> new DetectionCurveVo(Jcaa02a.getJcaa02a040(), Jcaa02a.getJcca31b030(),
                        Jcaa02a.getJcca31b180(), Jcaa02a.getJcaa02a060()))
                .collect(Collectors.toList());

        List<DetectionCurveVo> listZ = list.stream()
                .map(Jcaa02a -> new DetectionCurveVo(Jcaa02a.getJcaa02a040(), Jcaa02a.getJcca31b030(),
                        Jcaa02a.getJcca31b180(), Jcaa02a.getJcaa02a070()))
                .collect(Collectors.toList());

        DetectionCurveResultVo detectionCurveResultVo = new DetectionCurveResultVo();
        String monitorCode1 = listX.get(0).getMonitorCode();

        // 按日统计
        if ("3".equals(countLevel)) {
            listX = monitoringManagementUtils.getDetectionCurveDayMethod(listX, monitorCode1);
            listY = monitoringManagementUtils.getDetectionCurveDayMethod(listY, monitorCode1);
            listZ = monitoringManagementUtils.getDetectionCurveDayMethod(listZ, monitorCode1);
            detectionCurveResultVo = new DetectionCurveResultVo(listX, listY, listZ);
        } else
            // 按月统计
            if ("4".equals(countLevel)) {
                listX = monitoringManagementUtils.getDetectionCurveMonthMethod(listX, monitorCode1);
                listY = monitoringManagementUtils.getDetectionCurveMonthMethod(listX, monitorCode1);
                listZ = monitoringManagementUtils.getDetectionCurveMonthMethod(listX, monitorCode1);
                detectionCurveResultVo = new DetectionCurveResultVo(listX, listY, listZ);
            } else {
                detectionCurveResultVo = new DetectionCurveResultVo(listX, listY, listZ);
            }

        return detectionCurveResultVo;
    }



    /**
     * 加速度
     *
     * @param jsonObject
     * @return
     */
    @DS("master")
    @Override
    public DetectionCurveAccelerationResultVo queryDetectionCurveAcceleration(JSONObject jsonObject) {
        String dateTime = jsonObject.getString("dateTime");
        String startTime = jsonObject.getString("startTime");
        String endTime = jsonObject.getString("endTime");
        String countLevel = jsonObject.getString("countLevel");
        String dateLevel = jsonObject.getString("dateLevel");
        String monitorCode = jsonObject.getString("monitorCode");

        List<Jcaa04a> list = new ArrayList<>();
        if ("1".equals(dateLevel)) {
            list = monitoringManagementMapper.queryDetectionCurveAccelerationToday(dateTime, startTime, endTime, monitorCode);
        } else if ("3".equals(dateLevel)) {
            list = monitoringManagementMapper.queryDetectionCurveAccelerationThreeDay(dateTime, startTime, endTime, monitorCode);
        } else if ("7".equals(dateLevel)) {
            list = monitoringManagementMapper.queryDetectionCurveAccelerationSevenDay(dateTime, startTime, endTime, monitorCode);
        } else if ("15".equals(dateLevel)) {
            list = monitoringManagementMapper.queryDetectionCurveAccelerationFifteenDay(dateTime, startTime, endTime, monitorCode);
        } else if ("30".equals(dateLevel)) {
            list = monitoringManagementMapper.queryDetectionCurveAccelerationThirty(dateTime, startTime, endTime, monitorCode);
        } else {
            list = monitoringManagementMapper.queryDetectionCurveAcceleration(dateTime, startTime, endTime, monitorCode);
        }

        List<DetectionCurveAccelerationVo> listY = list.stream()
                .map(Jcaa04a -> new DetectionCurveAccelerationVo(Jcaa04a.getJcaa04a040(), Jcaa04a.getJcca31b030(),
                        Jcaa04a.getJcca31b180(), Jcaa04a.getJcaa04a050()
                ))
                .collect(Collectors.toList());

        List<DetectionCurveAccelerationVo> listX = list.stream()
                .map(Jcaa04a -> new DetectionCurveAccelerationVo(Jcaa04a.getJcaa04a040(), Jcaa04a.getJcca31b030(),
                        Jcaa04a.getJcca31b180(), Jcaa04a.getJcaa04a060()))
                .collect(Collectors.toList());


        List<DetectionCurveAccelerationVo> listZ = list.stream()
                .map(Jcaa04a -> new DetectionCurveAccelerationVo(Jcaa04a.getJcaa04a040(), Jcaa04a.getJcca31b030(),
                        Jcaa04a.getJcca31b180(), Jcaa04a.getJcaa04a070()))
                .collect(Collectors.toList());
        if(listX.size() == 0){
            return null;
        }
        String monitorCode1 = listX.get(0).getMonitorCode();
        DetectionCurveAccelerationResultVo resultVo = new DetectionCurveAccelerationResultVo();
        // 按日统计
        if (StringUtils.isNotEmpty(countLevel) && "3".equals(countLevel)) {
            listX = MonitoringManagementUtils.getDetectionCurveAccelerationDayMethod(listX, monitorCode1);
            listY = MonitoringManagementUtils.getDetectionCurveAccelerationDayMethod(listY, monitorCode1);
            listZ = MonitoringManagementUtils.getDetectionCurveAccelerationDayMethod(listZ, monitorCode1);
            resultVo = new DetectionCurveAccelerationResultVo(listX, listY, listZ);
        } else if (StringUtils.isNotEmpty(countLevel) && "4".equals(countLevel)) {
            listX = MonitoringManagementUtils.getDetectionCurveAccelerationMonthMonth(listX, monitorCode1);
            listY = MonitoringManagementUtils.getDetectionCurveAccelerationMonthMonth(listY, monitorCode1);
            listZ = MonitoringManagementUtils.getDetectionCurveAccelerationMonthMonth(listZ, monitorCode1);
            resultVo = new DetectionCurveAccelerationResultVo(listX, listY, listZ);
        } else {
            resultVo = new DetectionCurveAccelerationResultVo(listX, listY, listZ);
        }
        System.out.println("========================================================");
        System.out.println(resultVo);
        return resultVo;
    }

    /**
     * 倾角
     *
     * @param jsonObject
     * @return
     */
    @DS("master")
    @Override
    public DetectionCurveDipAngleResultVo queryDetectionCurveDipAngle(JSONObject jsonObject) {
        String dateTime = jsonObject.getString("dateTime");
        String startTime = jsonObject.getString("startTime");
        String endTime = jsonObject.getString("endTime");
        String dateLevel = jsonObject.getString("dateLevel");
        String countLevel = jsonObject.getString("countLevel");
        String monitorCode = jsonObject.getString("monitorCode");
        List<Jcaa05a> list = new ArrayList<>();
        if ("1".equals(dateLevel)) {
            list = monitoringManagementMapper.queryDetectionCurveDipAngleToday(dateTime, startTime, endTime, monitorCode);
        } else if ("3".equals(dateLevel)) {
            list = monitoringManagementMapper.queryDetectionCurveDipAngleThreeDay(dateTime, startTime, endTime, monitorCode);
        } else if ("7".equals(dateLevel)) {
            list = monitoringManagementMapper.queryDetectionCurveDipAngleSevenDay(dateTime, startTime, endTime, monitorCode);
        } else if ("15".equals(dateLevel)) {
            list = monitoringManagementMapper.queryDetectionCurveDipAngleFifteenDay(dateTime, startTime, endTime, monitorCode);
        } else if ("30".equals(dateLevel)) {
            list = monitoringManagementMapper.queryDetectionCurveDipAngleThirty(dateTime, startTime, endTime, monitorCode);
        } else {
            list = monitoringManagementMapper.queryDetectionCurveDipAngle(dateTime, startTime, endTime, monitorCode);
        }
        List<DetectionCurveDipAngleVo> listY = list.stream()
                .map(Jcaa05a -> new DetectionCurveDipAngleVo(Jcaa05a.getJcaa05a040(), Jcaa05a.getJcca31b030(),
                        Jcaa05a.getJcca31b180(), Jcaa05a.getJcaa05a050()))
                .collect(Collectors.toList());

        List<DetectionCurveDipAngleVo> listX = list.stream()
                .map(Jcaa05a -> new DetectionCurveDipAngleVo(Jcaa05a.getJcaa05a040(), Jcaa05a.getJcca31b030(),
                        Jcaa05a.getJcca31b180(), Jcaa05a.getJcaa05a060()))
                .collect(Collectors.toList());


        List<DetectionCurveDipAngleVo> listZ = list.stream()
                .map(Jcaa05a -> new DetectionCurveDipAngleVo(Jcaa05a.getJcaa05a040(), Jcaa05a.getJcca31b030(),
                        Jcaa05a.getJcca31b180(), Jcaa05a.getJcaa05a070()))
                .collect(Collectors.toList());


        List<DetectionCurveDipAngleVo> listMoveX = list.stream()
                .map(Jcaa05a -> new DetectionCurveDipAngleVo(Jcaa05a.getJcaa05a040(), Jcaa05a.getJcca31b030(),
                        Jcaa05a.getJcca31b180(), Jcaa05a.getJcaa05a100()))
                .collect(Collectors.toList());

        List<DetectionCurveDipAngleVo> listMoveY = list.stream()
                .map(Jcaa05a -> new DetectionCurveDipAngleVo(Jcaa05a.getJcaa05a040(), Jcaa05a.getJcca31b030(),
                        Jcaa05a.getJcca31b180(), Jcaa05a.getJcaa05a110()))
                .collect(Collectors.toList());


        List<DetectionCurveDipAngleVo> listMoveZ = list.stream()
                .map(Jcaa05a -> new DetectionCurveDipAngleVo(Jcaa05a.getJcaa05a040(), Jcaa05a.getJcca31b030(),
                        Jcaa05a.getJcca31b180(), Jcaa05a.getJcaa05a120()))
                .collect(Collectors.toList());


        List<DetectionCurveDipAngleVo> listDipAngle = list.stream()
                .map(Jcaa05a -> new DetectionCurveDipAngleVo(Jcaa05a.getJcaa05a040(), Jcaa05a.getJcca31b030(),
                        Jcaa05a.getJcca31b180(), Jcaa05a.getJcaa05a080()))
                .collect(Collectors.toList());


        List<DetectionCurveDipAngleVo> listAzimuthAngle = list.stream()
                .map(Jcaa05a -> new DetectionCurveDipAngleVo(Jcaa05a.getJcaa05a040(), Jcaa05a.getJcca31b030(),
                        Jcaa05a.getJcca31b180(), Jcaa05a.getJcaa05a090()))
                .collect(Collectors.toList());
        if(listY.size() == 0){
            return null;
        }
        String monitorCode1 = listY.get(0).getMonitorCode();
        DetectionCurveDipAngleResultVo resultVo = new DetectionCurveDipAngleResultVo();
        if (StringUtils.isNotEmpty(countLevel) && "3".equals(countLevel)) {
            listX = MonitoringManagementUtils.getDetectionCurveDipAngleDayMethod(listX, monitorCode1);
            listY = MonitoringManagementUtils.getDetectionCurveDipAngleDayMethod(listY, monitorCode1);
            listZ = MonitoringManagementUtils.getDetectionCurveDipAngleDayMethod(listZ, monitorCode1);
            listMoveX = MonitoringManagementUtils.getDetectionCurveDipAngleDayMethod(listMoveX, monitorCode1);
            listMoveY = MonitoringManagementUtils.getDetectionCurveDipAngleDayMethod(listMoveY, monitorCode1);
            listMoveZ = MonitoringManagementUtils.getDetectionCurveDipAngleDayMethod(listMoveZ, monitorCode1);
            listDipAngle = MonitoringManagementUtils.getDetectionCurveDipAngleDayMethod(listDipAngle, monitorCode1);
            listAzimuthAngle = MonitoringManagementUtils.getDetectionCurveDipAngleDayMethod(listAzimuthAngle, monitorCode1);
            resultVo = new DetectionCurveDipAngleResultVo(listX, listY, listZ,
                    listMoveX, listMoveY, listMoveZ, listDipAngle, listAzimuthAngle);
        } else if (StringUtils.isNotEmpty(countLevel) && "4".equals(countLevel)) {
            listX = MonitoringManagementUtils.getDetectionCurveDipAngleMonthMethod(listX, monitorCode1);
            listY = MonitoringManagementUtils.getDetectionCurveDipAngleMonthMethod(listY, monitorCode1);
            listZ = MonitoringManagementUtils.getDetectionCurveDipAngleMonthMethod(listZ, monitorCode1);
            listMoveX = MonitoringManagementUtils.getDetectionCurveDipAngleMonthMethod(listMoveX, monitorCode1);
            listMoveY = MonitoringManagementUtils.getDetectionCurveDipAngleMonthMethod(listMoveY, monitorCode1);
            listMoveZ = MonitoringManagementUtils.getDetectionCurveDipAngleMonthMethod(listMoveZ, monitorCode1);
            listDipAngle = MonitoringManagementUtils.getDetectionCurveDipAngleMonthMethod(listDipAngle, monitorCode1);
            listAzimuthAngle = MonitoringManagementUtils.getDetectionCurveDipAngleDayMethod(listAzimuthAngle, monitorCode1);
            resultVo = new DetectionCurveDipAngleResultVo(listX, listY, listZ,
                    listMoveX, listMoveY, listMoveZ, listDipAngle, listAzimuthAngle);
        } else {
            resultVo = new DetectionCurveDipAngleResultVo(listX, listY, listZ,
                    listMoveX, listMoveY, listMoveZ, listDipAngle, listAzimuthAngle);
        }
        return resultVo;
    }


    /**
     * 雨量
     *
     * @param jsonObject
     * @return
     */
    @DS("master")
    @Override
    public DetectionCurveRainfallResultVo queryDetectionCurveRainfall(JSONObject jsonObject) {
        String dateTime = jsonObject.getString("dateTime");
        String startTime = jsonObject.getString("startTime");
        String endTime = jsonObject.getString("endTime");
        String dateLevel = jsonObject.getString("dateLevel");
        String monitorCode = jsonObject.getString("monitorCode");
        String countLevel = jsonObject.getString("countLevel");
        List<Jcaa11a> list = new ArrayList<>();
        if ("1".equals(dateLevel)) {
            list = monitoringManagementMapper.queryDetectionCurveRainfallToday(dateTime, startTime, endTime, monitorCode);
        } else if ("3".equals(dateLevel)) {
            list = monitoringManagementMapper.queryDetectionCurveRainfallThreeDay(dateTime, startTime, endTime, monitorCode);
        } else if ("7".equals(dateLevel)) {
            list = monitoringManagementMapper.queryDetectionCurveRainfallSevenDay(dateTime, startTime, endTime, monitorCode);
        } else if ("15".equals(dateLevel)) {
            list = monitoringManagementMapper.queryDetectionCurveRainfallFifteenDay(dateTime, startTime, endTime, monitorCode);
        } else if ("30".equals(dateLevel)) {
            list = monitoringManagementMapper.queryDetectionCurveRainfallThirty(dateTime, startTime, endTime, monitorCode);
        } else {
            list = monitoringManagementMapper.queryDetectionCurveRainfall(dateTime, startTime, endTime, monitorCode);
        }
        //小时实时雨量
        List<DetectionCurveRainfallVo> rainfallList = list.stream()
                .map(Jcaa11a -> new DetectionCurveRainfallVo(Jcaa11a.getJcaa11a040(), Jcaa11a.getJcca31b030(),
                        Jcaa11a.getJcca31b180(), String.valueOf(Jcaa11a.getJcaa11a050())))
                .collect(Collectors.toList());
        List<DetectionCurveRainfallVo> rainfallCumulativeValueList = list.stream()
                .map(Jcaa11a -> new DetectionCurveRainfallVo(Jcaa11a.getJcaa11a040(), Jcaa11a.getJcca31b030(),
                        Jcaa11a.getJcca31b180(), Jcaa11a.getJcaa11a060()))
                .collect(Collectors.toList());

        List<DetectionCurveRainfallVo> rainfallSumCumulativeValueList = rainfallCumulativeValueList;
        DetectionCurveRainfallResultVo detectionCurveRainfallResultVo = new DetectionCurveRainfallResultVo();
        if ("3".equals(countLevel)) {
            //每天的累积雨量
            rainfallCumulativeValueList = MonitoringManagementUtils.getDetectionCurveRainfallDayMethod(rainfallCumulativeValueList);
            List<DetectionCurveRainfallVo> rainfallSumDayList = new ArrayList<>(rainfallCumulativeValueList);
            rainfallSumDayList = MonitoringManagementUtils.getDetectionCurveRainfallRunningTotalMethod(rainfallSumDayList);
            detectionCurveRainfallResultVo = new DetectionCurveRainfallResultVo(rainfallCumulativeValueList,
                    rainfallSumDayList);
        } else if ("4".equals(countLevel)) {
            //月的累积雨量
            rainfallCumulativeValueList = MonitoringManagementUtils
                    .getDetectionCurveRainfallMonthMethod(rainfallCumulativeValueList, monitorCode);
            List<DetectionCurveRainfallVo> rainfallSumMonthList = new ArrayList<>(rainfallCumulativeValueList);
            rainfallSumMonthList = MonitoringManagementUtils.getDetectionCurveRainfallRunningTotalMethod(rainfallSumMonthList);
            detectionCurveRainfallResultVo = new DetectionCurveRainfallResultVo(rainfallCumulativeValueList,
                    rainfallSumMonthList);
        } else {
            //小时
            List<DetectionCurveRainfallVo> rainfallSumList = new ArrayList<>(rainfallList);
            rainfallSumList = MonitoringManagementUtils.getDetectionCurveRainfallRunningTotalMethod(rainfallSumList);
            detectionCurveRainfallResultVo = new DetectionCurveRainfallResultVo(rainfallList,
                    rainfallSumList);
        }
        return detectionCurveRainfallResultVo;
    }


    /**
     * 气温
     *
     * @param jsonObject
     * @return
     */
    @DS("master")
    @Override
    public List<Jcaa12a> queryDetectionCurveAirTemperature(JSONObject jsonObject) {
        String dateTime = jsonObject.getString("dateTime");
        String startTime = jsonObject.getString("startTime");
        String endTime = jsonObject.getString("endTime");
        String dateLevel = jsonObject.getString("dateLevel");
        String countLevel = jsonObject.getString("countLevel");
        String monitorCode = jsonObject.getString("monitorCode");
        List<Jcaa12a> list = new ArrayList<>();
        if ("1".equals(dateLevel)) {
            list = monitoringManagementMapper.queryDetectionCurveAirTemperatureToday(dateTime, startTime, endTime, monitorCode);
        } else if ("3".equals(dateLevel)) {
            list = monitoringManagementMapper.queryDetectionCurveAirTemperatureThreeDay(dateTime, startTime, endTime, monitorCode);
        } else if ("7".equals(dateLevel)) {
            list = monitoringManagementMapper.queryDetectionCurveAirTemperatureSevenDay(dateTime, startTime, endTime, monitorCode);
        } else if ("15".equals(dateLevel)) {
            list = monitoringManagementMapper.queryDetectionCurveAirTemperatureFifteenDay(dateTime, startTime, endTime, monitorCode);
        } else if ("30".equals(dateLevel)) {
            list = monitoringManagementMapper.queryDetectionCurveAirTemperatureThirty(dateTime, startTime, endTime, monitorCode);
        } else {
            list = monitoringManagementMapper.queryDetectionCurveAirTemperature(dateTime, startTime, endTime, monitorCode);
        }


        if ("3".equals(countLevel)) {
            list = MonitoringManagementUtils.getDetectionCurveAirTemperatureDayMethod(list, monitorCode);
            return list;
        } else if ("4".equals(countLevel)) {
            list = MonitoringManagementUtils.getDetectionCurveAirTemperatureMonthMethod(list, monitorCode);
            return list;
        } else {
            return list;
        }

    }

    /**
     * 裂缝
     *
     * @param jsonObject
     * @return
     */
    @DS("master")
    @Override
    public TwoStringListVo queryDetectionCurveCrack(JSONObject jsonObject) {
        String dateTime = jsonObject.getString("dateTime");
        String startTime = jsonObject.getString("startTime");
        String endTime = jsonObject.getString("endTime");
        String dateLevel = jsonObject.getString("dateLevel");
        String monitorCode = jsonObject.getString("monitorCode");
        String countLevel = jsonObject.getString("countLevel");
        List<Jcaa01a> list = new ArrayList<>();
        if ("1".equals(dateLevel)) {
            list = monitoringManagementMapper.queryDetectionCurveCrackToday(dateTime, startTime, endTime, monitorCode);
        } else if ("3".equals(dateLevel)) {
            list = monitoringManagementMapper.queryDetectionCurveCrackThreeDay(dateTime, startTime, endTime, monitorCode);
        } else if ("7".equals(dateLevel)) {
            list = monitoringManagementMapper.queryDetectionCurveCrackSevenDay(dateTime, startTime, endTime, monitorCode);
        } else if ("15".equals(dateLevel)) {
            list = monitoringManagementMapper.queryDetectionCurveCrackFifteenDay(dateTime, startTime, endTime, monitorCode);
        } else if ("30".equals(dateLevel)) {
            list = monitoringManagementMapper.queryDetectionCurveCrackThirty(dateTime, startTime, endTime, monitorCode);
        } else {
            list = monitoringManagementMapper.queryDetectionCurveCrack(dateTime, startTime, endTime, monitorCode);
        }

        List<DetectionCurveCrackVo> crackCollectionValueList = list.stream()
                .map(Jcaa01a -> new DetectionCurveCrackVo(Jcaa01a.getJcca31b030(), Jcaa01a.getJcca31b180(),
                        Jcaa01a.getJcaa01a050(), String.valueOf(Jcaa01a.getJcaa01a040())))
                .collect(Collectors.toList());

        List<DetectionCurveCrackVo> crackChangeAmountList = list.stream()
                .map(Jcaa01a -> new DetectionCurveCrackVo(Jcaa01a.getJcca31b030(), Jcaa01a.getJcca31b180(),
                        Jcaa01a.getJcaa01a050(), String.valueOf(Jcaa01a.getJcaa01a060())))
                .collect(Collectors.toList());
        DetectionCurveCrackResultVo resultVo = new DetectionCurveCrackResultVo();
        if ("3".equals(countLevel)) {
            crackCollectionValueList = MonitoringManagementUtils
                    .getDetectionCurveCrackDayMethod(crackCollectionValueList, monitorCode);
            crackChangeAmountList = MonitoringManagementUtils
                    .getDetectionCurveCrackDayMethod(crackChangeAmountList, monitorCode);
            resultVo.setCrackCollectionValueList(crackCollectionValueList)
                    .setCrackChangeAmountList(crackChangeAmountList);
        } else if ("4".equals(countLevel)) {
            crackCollectionValueList = MonitoringManagementUtils
                    .getDetectionCurveCrackMonthMethod(crackCollectionValueList, monitorCode);
            crackChangeAmountList = MonitoringManagementUtils
                    .getDetectionCurveCrackMonthMethod(crackChangeAmountList, monitorCode);
            resultVo.setCrackCollectionValueList(crackCollectionValueList)
                    .setCrackChangeAmountList(crackChangeAmountList);
        } else {
            resultVo.setCrackCollectionValueList(crackCollectionValueList)
                    .setCrackChangeAmountList(crackChangeAmountList);
        }


        TwoStringListVo twoStringListVo = new TwoStringListVo(crackCollectionValueList, crackChangeAmountList);
        return twoStringListVo;
    }

    /**
     * 土壤含水率
     *
     * @param jsonObject
     * @return
     */
    @DS("master")
    @Override
    public List<Jcaa14a> queryDetectionCurveSoilMoistureContent(JSONObject jsonObject) {
        String dateTime = jsonObject.getString("dateTime");
        String startTime = jsonObject.getString("startTime");
        String endTime = jsonObject.getString("endTime");
        String dateLevel = jsonObject.getString("dateLevel");
        String countLevel = jsonObject.getString("countLevel");
        String monitorCode = jsonObject.getString("monitorCode");
        List<Jcaa14a> list = new ArrayList<>();
        if ("1".equals(dateLevel)) {
            list = monitoringManagementMapper.queryDetectionCurveSoilMoistureContentToday(dateTime, startTime, endTime, monitorCode);
        } else if ("3".equals(dateLevel)) {
            list = monitoringManagementMapper.queryDetectionCurveSoilMoistureContentThreeDay(dateTime, startTime, endTime, monitorCode);
        } else if ("7".equals(dateLevel)) {
            list = monitoringManagementMapper.queryDetectionCurveSoilMoistureContentSevenDay(dateTime, startTime, endTime, monitorCode);
        } else if ("15".equals(dateLevel)) {
            list = monitoringManagementMapper.queryDetectionCurveSoilMoistureContentFifteenDay(dateTime, startTime, endTime, monitorCode);
        } else if ("30".equals(dateLevel)) {
            list = monitoringManagementMapper.queryDetectionCurveSoilMoistureContentThirty(dateTime, startTime, endTime, monitorCode);
        } else {
            list = monitoringManagementMapper.queryDetectionCurveSoilMoistureContent(dateTime, startTime, endTime, monitorCode);
        }

        if ("3".equals(countLevel)) {
            list = MonitoringManagementUtils.getDetectionCurveSoilMoistureContentDayMethod(list, monitorCode);
            return list;
        } else if ("4".equals(countLevel)) {
            list = MonitoringManagementUtils.getDetectionCurveSoilMoistureContentMonthMethod(list, monitorCode);
            return list;
        } else {
            return list;
        }
    }

    /**
     * 泥水位
     *
     * @param jsonObject
     * @return
     */
    @DS("master")
    @Override
    public List<Jcaa22a> queryDetectionCurveMudWaterLevel(JSONObject jsonObject) {
        String dateTime = jsonObject.getString("dateTime");
        String startTime = jsonObject.getString("startTime");
        String endTime = jsonObject.getString("endTime");
        String dateLevel = jsonObject.getString("dateLevel");
        String monitorCode = jsonObject.getString("monitorCode");
        String countLevel = jsonObject.getString("countLevel");
        List<Jcaa22a> list = new ArrayList<>();
        if ("1".equals(dateLevel)) {
            list = monitoringManagementMapper.queryDetectionCurveMudWaterLevelToday(dateTime, startTime, endTime, monitorCode);
        } else if ("3".equals(dateLevel)) {
            list = monitoringManagementMapper.queryDetectionCurveMudWaterLevelThreeDay(dateTime, startTime, endTime, monitorCode);
        } else if ("7".equals(dateLevel)) {
            list = monitoringManagementMapper.queryDetectionCurveMudWaterLevelSevenDay(dateTime, startTime, endTime, monitorCode);
        } else if ("15".equals(dateLevel)) {
            list = monitoringManagementMapper.queryDetectionCurveMudWaterLevelFifteenDay(dateTime, startTime, endTime, monitorCode);
        } else if ("30".equals(dateLevel)) {
            list = monitoringManagementMapper.queryDetectionCurveMudWaterLevelThirty(dateTime, startTime, endTime, monitorCode);
        } else {
            list = monitoringManagementMapper.queryDetectionCurveMudWaterLevel(dateTime, startTime, endTime, monitorCode);
        }
        if ("3".equals(countLevel)) {
            list = MonitoringManagementUtils.getDetectionCurveMudWaterLevelDayMethod(list, monitorCode);
            return list;
        } else if ("4".equals(countLevel)) {
            list = MonitoringManagementUtils.getDetectionCurveMudWaterLevelMonthMethod(list, monitorCode);
            return list;
        } else {
            return list;
        }

    }

    /**
     * 气压
     *
     * @param jsonObject
     * @return
     */
    @DS("master")
    @Override
    public List<Jcaa21a> queryDetectionCurvePressure(JSONObject jsonObject) {
        String dateTime = jsonObject.getString("dateTime");
        String startTime = jsonObject.getString("startTime");
        String endTime = jsonObject.getString("endTime");
        String dateLevel = jsonObject.getString("dateLevel");
        String monitorCode = jsonObject.getString("monitorCode");
        String countLevel = jsonObject.getString("countLevel");
        List<Jcaa21a> list = new ArrayList<>();
        if ("1".equals(dateLevel)) {
            list = monitoringManagementMapper.queryDetectionCurvePressureToday(dateTime, startTime, endTime, monitorCode);
        } else if ("3".equals(dateLevel)) {
            list = monitoringManagementMapper.queryDetectionCurvePressureThreeDay(dateTime, startTime, endTime, monitorCode);
        } else if ("7".equals(dateLevel)) {
            list = monitoringManagementMapper.queryDetectionCurvePressureSevenDay(dateTime, startTime, endTime, monitorCode);
        } else if ("15".equals(dateLevel)) {
            list = monitoringManagementMapper.queryDetectionCurvePressureFifteenDay(dateTime, startTime, endTime, monitorCode);
        } else if ("30".equals(dateLevel)) {
            list = monitoringManagementMapper.queryDetectionCurvePressureThirty(dateTime, startTime, endTime, monitorCode);
        } else {
            list = monitoringManagementMapper.queryDetectionCurvePressure(dateTime, startTime, endTime, monitorCode);
        }

        if ("3".equals(countLevel)) {
            list = MonitoringManagementUtils.getDetectionCurvePressureDayMethod(list, monitorCode);
            return list;
        } else if ("4".equals(countLevel)) {
            list = MonitoringManagementUtils.getDetectionCurvePressureMonthMethod(list, monitorCode);
            return list;
        } else {
            return list;
        }
    }

    /**
     * 振动
     *
     * @param jsonObject
     * @return
     */
    @DS("master")
    @Override
    public DetectionCurveCrackListVo queryDetectionCurveVibrate(JSONObject jsonObject) {
        String dateTime = jsonObject.getString("dateTime");
        String startTime = jsonObject.getString("startTime");
        String endTime = jsonObject.getString("endTime");
        String dateLevel = jsonObject.getString("dateLevel");
        String monitorCode = jsonObject.getString("monitorCode");
        String countLevel = jsonObject.getString("countLevel");
        List<Jcca06a> list = new ArrayList<>();
        if ("1".equals(dateLevel)) {
            list = monitoringManagementMapper.queryDetectionCurveVibrateToday(dateTime, startTime, endTime, monitorCode);
        } else if ("3".equals(dateLevel)) {
            list = monitoringManagementMapper.queryDetectionCurveVibrateThreeDay(dateTime, startTime, endTime, monitorCode);
        } else if ("7".equals(dateLevel)) {
            list = monitoringManagementMapper.queryDetectionCurveVibrateSevenDay(dateTime, startTime, endTime, monitorCode);
        } else if ("15".equals(dateLevel)) {
            list = monitoringManagementMapper.queryDetectionCurveVibrateFifteenDay(dateTime, startTime, endTime, monitorCode);
        } else if ("30".equals(dateLevel)) {
            list = monitoringManagementMapper.queryDetectionCurveVibrateThirty(dateTime, startTime, endTime, monitorCode);
        } else {
            list = monitoringManagementMapper.queryDetectionCurveVibrate(dateTime, startTime, endTime, monitorCode);
        }
        List<DetectionCurveCrackVo> vibrationFrequencyXList = list.stream()
                .map(Jcca06a -> new DetectionCurveCrackVo(Jcca06a.getJcca31b030(), Jcca06a.getJcca31b180(),
                        Jcca06a.getJcaa06a040(), String.valueOf(Jcca06a.getJcaa06a050())))
                .collect(Collectors.toList());
        List<DetectionCurveCrackVo> vibrationFrequencyYList = list.stream()
                .map(Jcca06a -> new DetectionCurveCrackVo(Jcca06a.getJcca31b030(), Jcca06a.getJcca31b180(),
                        Jcca06a.getJcaa06a040(), String.valueOf(Jcca06a.getJcaa06a060())))
                .collect(Collectors.toList());
        List<DetectionCurveCrackVo> vibrationFrequencyZList = list.stream()
                .map(Jcca06a -> new DetectionCurveCrackVo(Jcca06a.getJcca31b030(), Jcca06a.getJcca31b180(),
                        Jcca06a.getJcaa06a040(), String.valueOf(Jcca06a.getJcaa06a070())))
                .collect(Collectors.toList());
        List<DetectionCurveCrackVo> vibrationAmplitudeList = list.stream()
                .map(Jcca06a -> new DetectionCurveCrackVo(Jcca06a.getJcca31b030(), Jcca06a.getJcca31b180(),
                        Jcca06a.getJcaa06a040(), String.valueOf(Jcca06a.getJcaa06a080())))
                .collect(Collectors.toList());
        List<DetectionCurveCrackVo> instantaneousDisplacementXList = list.stream()
                .map(Jcca06a -> new DetectionCurveCrackVo(Jcca06a.getJcca31b030(), Jcca06a.getJcca31b180(),
                        Jcca06a.getJcaa06a040(), String.valueOf(Jcca06a.getJcaa06a090())))
                .collect(Collectors.toList());
        List<DetectionCurveCrackVo> instantaneousDisplacementSynthesisDirectionList = list.stream()
                .map(Jcca06a -> new DetectionCurveCrackVo(Jcca06a.getJcca31b030(), Jcca06a.getJcca31b180(),
                        Jcca06a.getJcaa06a040(), String.valueOf(Jcca06a.getJcaa06a100())))
                .collect(Collectors.toList());
        List<DetectionCurveCrackVo> instantaneousDisplacementZList = list.stream()
                .map(Jcca06a -> new DetectionCurveCrackVo(Jcca06a.getJcca31b030(), Jcca06a.getJcca31b180(),
                        Jcca06a.getJcaa06a040(), String.valueOf(Jcca06a.getJcaa06a110())))
                .collect(Collectors.toList());
        List<DetectionCurveCrackVo> instantaneousDisplacementYList = list.stream()
                .map(Jcca06a -> new DetectionCurveCrackVo(Jcca06a.getJcca31b030(), Jcca06a.getJcca31b180(),
                        Jcca06a.getJcaa06a040(), String.valueOf(Jcca06a.getJcaa06a120())))
                .collect(Collectors.toList());
        DetectionCurveCrackListVo detectionCurveCrackListVo = new DetectionCurveCrackListVo();
        if ("3".equals(countLevel)) {
            vibrationFrequencyXList = MonitoringManagementUtils
                    .getDetectionCurveVibrateDayMethod(vibrationFrequencyXList,monitorCode);

            vibrationFrequencyYList = MonitoringManagementUtils
                    .getDetectionCurveVibrateDayMethod(vibrationFrequencyYList,monitorCode);

            vibrationFrequencyZList = MonitoringManagementUtils
                    .getDetectionCurveVibrateDayMethod(vibrationFrequencyZList,monitorCode);

            vibrationAmplitudeList = MonitoringManagementUtils
                    .getDetectionCurveVibrateDayMethod(vibrationAmplitudeList,monitorCode);

            instantaneousDisplacementXList = MonitoringManagementUtils
                    .getDetectionCurveVibrateDayMethod(instantaneousDisplacementXList,monitorCode);

            instantaneousDisplacementSynthesisDirectionList = MonitoringManagementUtils
                    .getDetectionCurveVibrateDayMethod(instantaneousDisplacementSynthesisDirectionList,monitorCode);

            instantaneousDisplacementZList = MonitoringManagementUtils
                    .getDetectionCurveVibrateDayMethod(instantaneousDisplacementZList,monitorCode);

            instantaneousDisplacementYList = MonitoringManagementUtils
                    .getDetectionCurveVibrateDayMethod(instantaneousDisplacementYList,monitorCode);
            detectionCurveCrackListVo = new DetectionCurveCrackListVo(vibrationFrequencyXList,
                    vibrationFrequencyYList,
                    vibrationFrequencyZList,
                    vibrationAmplitudeList,
                    instantaneousDisplacementXList,
                    instantaneousDisplacementSynthesisDirectionList,
                    instantaneousDisplacementZList,
                    instantaneousDisplacementYList);
        } else if ("4".equals(countLevel)) {
            vibrationFrequencyXList = MonitoringManagementUtils
                    .getDetectionCurveVibrateMonthMethod(vibrationFrequencyXList,monitorCode);

            vibrationFrequencyYList = MonitoringManagementUtils
                    .getDetectionCurveVibrateMonthMethod(vibrationFrequencyYList,monitorCode);

            vibrationFrequencyZList = MonitoringManagementUtils
                    .getDetectionCurveVibrateMonthMethod(vibrationFrequencyZList,monitorCode);

            vibrationAmplitudeList = MonitoringManagementUtils
                    .getDetectionCurveVibrateMonthMethod(vibrationAmplitudeList,monitorCode);

            instantaneousDisplacementXList = MonitoringManagementUtils
                    .getDetectionCurveVibrateMonthMethod(instantaneousDisplacementXList,monitorCode);

            instantaneousDisplacementSynthesisDirectionList = MonitoringManagementUtils
                    .getDetectionCurveVibrateMonthMethod(instantaneousDisplacementSynthesisDirectionList,monitorCode);

            instantaneousDisplacementZList = MonitoringManagementUtils
                    .getDetectionCurveVibrateMonthMethod(instantaneousDisplacementZList,monitorCode);

            instantaneousDisplacementYList = MonitoringManagementUtils
                    .getDetectionCurveVibrateMonthMethod(instantaneousDisplacementYList,monitorCode);
            detectionCurveCrackListVo = new DetectionCurveCrackListVo(vibrationFrequencyXList,
                    vibrationFrequencyYList,
                    vibrationFrequencyZList,
                    vibrationAmplitudeList,
                    instantaneousDisplacementXList,
                    instantaneousDisplacementSynthesisDirectionList,
                    instantaneousDisplacementZList,
                    instantaneousDisplacementYList);
        }else {
            detectionCurveCrackListVo = new DetectionCurveCrackListVo(vibrationFrequencyXList,
                    vibrationFrequencyYList,
                    vibrationFrequencyZList,
                    vibrationAmplitudeList,
                    instantaneousDisplacementXList,
                    instantaneousDisplacementSynthesisDirectionList,
                    instantaneousDisplacementZList,
                    instantaneousDisplacementYList);
        }
        return detectionCurveCrackListVo;
    }

    /**
     * 深部位移
     *
     * @param jsonObject
     * @return
     */
    @DS("master")
    @Override
    public DetectionCurveDeepDisplacementResultVo queryDetectionCurveDeepDisplacement(JSONObject jsonObject) {
        String dateTime = jsonObject.getString("dateTime");
        String startTime = jsonObject.getString("startTime");
        String endTime = jsonObject.getString("endTime");
        String dateLevel = jsonObject.getString("dateLevel");
        String monitorCode = jsonObject.getString("monitorCode");
        String countLevel = jsonObject.getString("countLevel");
        List<Jcaa03a> list = new ArrayList<>();
        if ("1".equals(dateLevel)) {
            list = monitoringManagementMapper.queryDetectionCurveDeepDisplacementToday(dateTime, startTime, endTime, monitorCode);
        } else if ("3".equals(dateLevel)) {
            list = monitoringManagementMapper.queryDetectionCurveDeepDisplacementThreeDay(dateTime, startTime, endTime, monitorCode);
        } else if ("7".equals(dateLevel)) {
            list = monitoringManagementMapper.queryDetectionCurveDeepDisplacementSevenDay(dateTime, startTime, endTime, monitorCode);
        } else if ("15".equals(dateLevel)) {
            list = monitoringManagementMapper.queryDetectionCurveDeepDisplacementFifteenDay(dateTime, startTime, endTime, monitorCode);
        } else if ("30".equals(dateLevel)) {
            list = monitoringManagementMapper.queryDetectionCurveDeepDisplacementThirty(dateTime, startTime, endTime, monitorCode);
        } else {
            list = monitoringManagementMapper.queryDetectionCurveDeepDisplacement(dateTime, startTime, endTime, monitorCode);
        }

        List<DetectionCurveDeepDisplacementVo> parallelVariationList = list.stream()
                .map(Jcaa03a -> new DetectionCurveDeepDisplacementVo(Jcaa03a.getJcca31b030(), Jcaa03a.getJcca31b180(),
                        Jcaa03a.getJcaa03a040(), String.valueOf(Jcaa03a.getJcaa03a050())))
                .collect(Collectors.toList());
        List<DetectionCurveDeepDisplacementVo> verticalVariationList = list.stream()
                .map(Jcaa03a -> new DetectionCurveDeepDisplacementVo(Jcaa03a.getJcca31b030(), Jcaa03a.getJcca31b180(),
                        Jcaa03a.getJcaa03a040(), String.valueOf(Jcaa03a.getJcaa03a060())))
                .collect(Collectors.toList());

         DetectionCurveDeepDisplacementResultVo resultVo = new DetectionCurveDeepDisplacementResultVo();
        if ("3".equals(countLevel)) {
            parallelVariationList = MonitoringManagementUtils
                    .getDetectionCurveDeepDisplacementDayMethod(parallelVariationList,monitorCode);
            verticalVariationList = MonitoringManagementUtils
                    .getDetectionCurveDeepDisplacementDayMethod(verticalVariationList,monitorCode);
            resultVo.setParallelVariationList(parallelVariationList).setVerticalVariationList(verticalVariationList);
        } else if ("4".equals(countLevel)) {
            parallelVariationList = MonitoringManagementUtils
                    .getDetectionCurveDeepDisplacementMonthMethod(parallelVariationList,monitorCode);
            verticalVariationList = MonitoringManagementUtils
                    .getDetectionCurveDeepDisplacementMonthMethod(verticalVariationList,monitorCode);
            resultVo.setParallelVariationList(parallelVariationList).setVerticalVariationList(verticalVariationList);
        }else {
            resultVo.setParallelVariationList(parallelVariationList).setVerticalVariationList(verticalVariationList);
        }
        return resultVo;
    }

    /**
     * 土压力
     *
     * @param jsonObject
     * @return
     */
    @DS("master")
    @Override
    public List<Jcaa08a> queryDetectionCurveSoilPressure(JSONObject jsonObject) {
        String dateTime = jsonObject.getString("dateTime");
        String startTime = jsonObject.getString("startTime");
        String endTime = jsonObject.getString("endTime");
        String dateLevel = jsonObject.getString("dateLevel");
        String monitorCode = jsonObject.getString("monitorCode");
        String countLevel = jsonObject.getString("countLevel");
        List<Jcaa08a> list = new ArrayList<>();
        if ("1".equals(dateLevel)) {
            list = monitoringManagementMapper.queryDetectionCurveSoilPressureToday(dateTime, startTime, endTime, monitorCode);
        } else if ("3".equals(dateLevel)) {
            list = monitoringManagementMapper.queryDetectionCurveSoilPressureThreeDay(dateTime, startTime, endTime, monitorCode);
        } else if ("7".equals(dateLevel)) {
            list = monitoringManagementMapper.queryDetectionCurveSoilPressureSevenDay(dateTime, startTime, endTime, monitorCode);
        } else if ("15".equals(dateLevel)) {
            list = monitoringManagementMapper.queryDetectionCurveSoilPressureFifteenDay(dateTime, startTime, endTime, monitorCode);
        } else if ("30".equals(dateLevel)) {
            list = monitoringManagementMapper.queryDetectionCurveSoilPressureThirty(dateTime, startTime, endTime, monitorCode);
        } else {
            list = monitoringManagementMapper.queryDetectionCurveSoilPressure(dateTime, startTime, endTime, monitorCode);
        }

        if ("3".equals(countLevel)) {
            list = MonitoringManagementUtils.getDetectionCurveSoilPressureDayMethod(list, monitorCode);
            return list;
        } else if ("4".equals(countLevel)) {
            list = MonitoringManagementUtils.getDetectionCurveSoilPressureMonthMethod(list, monitorCode);
            return list;
        } else {
            return list;
        }
    }
    /**
     * 土壤温度
     *
     * @param jsonObject
     * @return
     */
    @DS("master")
    @Override
    public List<Jcaa13a> queryDetectionCurveSoilTempera(JSONObject jsonObject) {
        String dateTime = jsonObject.getString("dateTime");
        String startTime = jsonObject.getString("startTime");
        String endTime = jsonObject.getString("endTime");
        String dateLevel = jsonObject.getString("dateLevel");
        String monitorCode = jsonObject.getString("monitorCode");
        String countLevel = jsonObject.getString("countLevel");
        List<Jcaa13a> list = new ArrayList<>();
        if ("1".equals(dateLevel)) {
            list = monitoringManagementMapper.queryDetectionCurveSoilTemperaToday(dateTime, startTime, endTime, monitorCode);
        } else if ("3".equals(dateLevel)) {
            list = monitoringManagementMapper.queryDetectionCurveSoilTemperaThreeDay(dateTime, startTime, endTime, monitorCode);
        } else if ("7".equals(dateLevel)) {
            list = monitoringManagementMapper.queryDetectionCurveSoilTemperaSevenDay(dateTime, startTime, endTime, monitorCode);
        } else if ("15".equals(dateLevel)) {
            list = monitoringManagementMapper.queryDetectionCurveSoilTemperaFifteenDay(dateTime, startTime, endTime, monitorCode);
        } else if ("30".equals(dateLevel)) {
            list = monitoringManagementMapper.queryDetectionCurveSoilTemperaThirty(dateTime, startTime, endTime, monitorCode);
        } else {
            list = monitoringManagementMapper.queryDetectionCurveSoilTempera(dateTime, startTime, endTime, monitorCode);
        }

        if ("3".equals(countLevel)) {
            list = MonitoringManagementUtils.getDetectionCurveSoilTemperaDayMethod(list, monitorCode);
            return list;
        } else if ("4".equals(countLevel)) {
            list = MonitoringManagementUtils.getDetectionCurveSoilTemperaMonthMethod(list, monitorCode);
            return list;
        } else {
            return list;
        }
    }

    /**
     * 地下水位水温
     *
     * @param jsonObject
     * @return
     */
    @DS("master")
    @Override
    public DetectionCurveUndergroundWaterLevelTemperaResultVo queryDetectionCurveUndergroundWaterLevelTempera(JSONObject jsonObject) {
        String dateTime = jsonObject.getString("dateTime");
        String startTime = jsonObject.getString("startTime");
        String endTime = jsonObject.getString("endTime");
        String dateLevel = jsonObject.getString("dateLevel");
        String monitorCode = jsonObject.getString("monitorCode");
        String countLevel = jsonObject.getString("countLevel");
        List<Jcaa16a> list = new ArrayList<>();
        if ("1".equals(dateLevel)) {
            list = monitoringManagementMapper.queryDetectionCurveUndergroundWaterLevelTemperaToday(dateTime, startTime, endTime, monitorCode);
        } else if ("3".equals(dateLevel)) {
            list = monitoringManagementMapper.queryDetectionCurveUndergroundWaterLevelTemperaThreeDay(dateTime, startTime, endTime, monitorCode);
        } else if ("7".equals(dateLevel)) {
            list = monitoringManagementMapper.queryDetectionCurveUndergroundWaterLevelTemperaSevenDay(dateTime, startTime, endTime, monitorCode);
        } else if ("15".equals(dateLevel)) {
            list = monitoringManagementMapper.queryDetectionCurveUndergroundWaterLevelTemperaFifteenDay(dateTime, startTime, endTime, monitorCode);
        } else if ("30".equals(dateLevel)) {
            list = monitoringManagementMapper.queryDetectionCurveUndergroundWaterLevelTemperaThirty(dateTime, startTime, endTime, monitorCode);
        } else {
            list = monitoringManagementMapper.queryDetectionCurveUndergroundWaterLevelTempera(dateTime, startTime, endTime, monitorCode);
        }

        List<DetectionCurveUndergroundWaterLevelTemperaVo> temperatureList = list.stream()
                .map(Jcaa16a -> new DetectionCurveUndergroundWaterLevelTemperaVo(Jcaa16a.getJcca31b030(), Jcaa16a.getJcca31b180(),
                        Jcaa16a.getJcaa16a040(), String.valueOf(Jcaa16a.getJcaa16a050())))
                .collect(Collectors.toList());
        List<DetectionCurveUndergroundWaterLevelTemperaVo> pressureList = list.stream()
                .map(Jcaa16a -> new DetectionCurveUndergroundWaterLevelTemperaVo(Jcaa16a.getJcca31b030(), Jcaa16a.getJcca31b180(),
                        Jcaa16a.getJcaa16a040(), String.valueOf(Jcaa16a.getJcaa16a060())))
                .collect(Collectors.toList());

        DetectionCurveUndergroundWaterLevelTemperaResultVo resultVo = new DetectionCurveUndergroundWaterLevelTemperaResultVo();
        if ("3".equals(countLevel)) {
            temperatureList = MonitoringManagementUtils
                    .getDetectionCurveUndergroundWaterLevelTemperaDayMethod(temperatureList,monitorCode);
            pressureList = MonitoringManagementUtils
                    .getDetectionCurveUndergroundWaterLevelTemperaDayMethod(pressureList,monitorCode);
            resultVo.setTemperatureList(temperatureList).setPressureList(pressureList);
        } else if ("4".equals(countLevel)) {
            temperatureList = MonitoringManagementUtils
                    .getDetectionCurveUndergroundWaterLevelTemperaMonthMethod(temperatureList,monitorCode);
            pressureList = MonitoringManagementUtils
                    .getDetectionCurveUndergroundWaterLevelTemperaMonthMethod(pressureList,monitorCode);
            resultVo.setTemperatureList(temperatureList).setPressureList(pressureList);
        }else {
            resultVo.setTemperatureList(temperatureList).setPressureList(pressureList);
        }
        return resultVo;
    }

    /**
     * 孔隙水压力监测
     *
     * @param jsonObject
     * @return
     */
    @DS("master")
    @Override
    public DetectionCurvePoreWaterPressureResultVo queryDetectionCurvePoreWaterPressure(JSONObject jsonObject) {
        String dateTime = jsonObject.getString("dateTime");
        String startTime = jsonObject.getString("startTime");
        String endTime = jsonObject.getString("endTime");
        String dateLevel = jsonObject.getString("dateLevel");
        String monitorCode = jsonObject.getString("monitorCode");
        String countLevel = jsonObject.getString("countLevel");
        List<Jcaa17a> list = new ArrayList<>();
        if ("1".equals(dateLevel)) {
            list = monitoringManagementMapper.queryDetectionCurvePoreWaterPressureToday(dateTime, startTime, endTime, monitorCode);
        } else if ("3".equals(dateLevel)) {
            list = monitoringManagementMapper.queryDetectionCurvePoreWaterPressureThreeDay(dateTime, startTime, endTime, monitorCode);
        } else if ("7".equals(dateLevel)) {
            list = monitoringManagementMapper.queryDetectionCurvePoreWaterPressureSevenDay(dateTime, startTime, endTime, monitorCode);
        } else if ("15".equals(dateLevel)) {
            list = monitoringManagementMapper.queryDetectionCurvePoreWaterPressureFifteenDay(dateTime, startTime, endTime, monitorCode);
        } else if ("30".equals(dateLevel)) {
            list = monitoringManagementMapper.queryDetectionCurvePoreWaterPressureThirty(dateTime, startTime, endTime, monitorCode);
        } else {
            list = monitoringManagementMapper.queryDetectionCurvePoreWaterPressure(dateTime, startTime, endTime, monitorCode);
        }

        List<DetectionCurvePoreWaterPressureVo> temperatureList = list.stream()
                .map(Jcaa17a -> new DetectionCurvePoreWaterPressureVo(Jcaa17a.getJcca31b030(), Jcaa17a.getJcca31b180(),
                        Jcaa17a.getJcaa17a040(), String.valueOf(Jcaa17a.getJcaa17a050())))
                .collect(Collectors.toList());
        List<DetectionCurvePoreWaterPressureVo> pressureList = list.stream()
                .map(Jcaa17a -> new DetectionCurvePoreWaterPressureVo(Jcaa17a.getJcca31b030(), Jcaa17a.getJcca31b180(),
                        Jcaa17a.getJcaa17a040(), String.valueOf(Jcaa17a.getJcaa17a060())))
                .collect(Collectors.toList());

        DetectionCurvePoreWaterPressureResultVo resultVo = new DetectionCurvePoreWaterPressureResultVo();
        if ("3".equals(countLevel)) {
            temperatureList = MonitoringManagementUtils
                    .getDetectionCurvePoreWaterPressureDayMethod(temperatureList,monitorCode);
            pressureList = MonitoringManagementUtils
                    .getDetectionCurvePoreWaterPressureDayMethod(pressureList,monitorCode);
            resultVo.setTemperatureList(temperatureList).setPressureList(pressureList);
        } else if ("4".equals(countLevel)) {
            temperatureList = MonitoringManagementUtils
                    .getDetectionCurvePoreWaterPressureMonthMethod(temperatureList,monitorCode);
            pressureList = MonitoringManagementUtils
                    .getDetectionCurvePoreWaterPressureMonthMethod(pressureList,monitorCode);
            resultVo.setTemperatureList(temperatureList).setPressureList(pressureList);
        }else {
            resultVo.setTemperatureList(temperatureList).setPressureList(pressureList);
        }
        return resultVo;
    }


    @DS("slave_qxdata")
    @Override
    public List<WaringModelVo> queryWaringModel(JSONObject jsonObject) {
        if (JSONUtil.parseObj(jsonObject).isEmpty()) {
            return null;
        }
        String singleOrMultipleParameters = jsonObject.getString("singleOrMultipleParameters");
        String warningFrequency = jsonObject.getString("warningFrequency");
        String monitorCode = jsonObject.getString("monitorCode");
        List<WaringModelVo> list = monitoringManagementMapper.queryWaringModel(singleOrMultipleParameters,
                warningFrequency, monitorCode);

        return list;
    }


    /**
     * 更新判据
     *
     * @param jsonObject
     * @return
     */
    @Transactional
    @DS("slave_qxdata")
    @Override
    public int updateExpression(JSONObject jsonObject) {
        if (JSONUtil.parseObj(jsonObject).isEmpty()) {
            return 0;
        }
        String monitorCode = jsonObject.getString("monitorCode");
        String waringType = jsonObject.getString("waringType");
        String monitorExpression = jsonObject.getString("monitorExpression");
        System.out.println("===========================================" + waringType);
        System.out.println(monitorCode);
        System.out.println(monitorExpression);
        int result = monitoringManagementMapper.updateExpression(monitorCode, waringType, monitorExpression);

        return result;
    }

    /**
     * 删除判据
     *
     * @param jsonObject
     * @return
     */
    @DS("slave_qxdata")
    @Transactional
    @Override
    public int deleteCriterionDelete(JSONObject jsonObject) {
        if (JSONUtil.parseObj(jsonObject).isEmpty()) {
            return 0;
        }
        String monitorCode = jsonObject.getString("monitorCode");
        String waringType = jsonObject.getString("waringType");
        int result = monitoringManagementMapper.deleteCriterionDelete(monitorCode, waringType);
        return result;
    }


}


